package com.jial08.tools.RedisTest.controller;

import com.jial08.tools.RedisTest.entity.User;
import com.jial08.tools.common.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>类描述：。</p>
 *
 * @author jl
 * @version v1.0.0.1。
 * @since JDK1.8。
 * <p>创建日期：2019/4/24 16:35。</p>
 */
@RestController
@RequestMapping("redis")
public class RedisController {
    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("set")
    public void set() {
        User user = new User();
        user.setName("王五");
        user.setAddress("龙鳞路");
        user.setAge(20);
        redisUtil.set("user", user);
        List<User> list = new ArrayList();
        list.add(user);
        redisUtil.set("list", list);
    }

    @RequestMapping("get")
    public Object get() {
        User user = redisUtil.get("user");
        List<User> list = redisUtil.get("list");
        Map map = new HashMap();
        map.put("user", user);
        map.put("list", list);
        return map;
    }
}
